package com.ruoyi.eam.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamType;
import com.ruoyi.eam.service.IEamTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产类型Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/type")
public class EamTypeController extends BaseController
{
    @Autowired
    private IEamTypeService eamTypeService;

    /**
     * 查询资产类型列表
     */
//    @RequiresPermissions("system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(EamType eamType)
    {
        startPage();
        List<EamType> list = eamTypeService.selectEamTypeList(eamType);
        return getDataTable(list);
    }

    @GetMapping("/typeList")
    public TableDataInfo typeList(EamType eamType)
    {
        startPage();
        List<EamType> list = eamTypeService.selectDictTypeParentId();
        return getDataTable(list);
    }


    /**
     * 导出资产类型列表
     */
    //@RequiresPermissions("system:type:export")
    @Log(title = "资产类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamType eamType)
    {
        List<EamType> list = eamTypeService.selectEamTypeList(eamType);
        ExcelUtil<EamType> util = new ExcelUtil<EamType>(EamType.class);
        util.exportExcel(response, list, "资产类型数据");
    }

    /**
     * 获取资产类型详细信息
     */
    //@RequiresPermissions("system:type:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(eamTypeService.selectEamTypeByTypeId(typeId));
    }

    /**
     * 新增资产类型
     */
    //@RequiresPermissions("system:type:add")
    @Log(title = "资产类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamType eamType)
    {
        return toAjax(eamTypeService.insertEamType(eamType));
    }

    /**
     * 修改资产类型
     */
    //@RequiresPermissions("system:type:edit")
    @Log(title = "资产类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamType eamType)
    {
        return toAjax(eamTypeService.updateEamType(eamType));
    }

    /**
     * 删除资产类型
     */
    //@RequiresPermissions("system:type:remove")
    @Log(title = "资产类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(eamTypeService.deleteEamTypeByTypeIds(typeIds));
    }
}
